<template>
  <div class="parent-node">
    <div
      v-for="item in menuData"
      :key="item.content_id"
      class="main"
      :class="{ active: item.content_id === curContentId }"
    >
      <div class="circle-line w-18px">
        <div class="circle"></div>
        <div class="line"></div>
      </div>

      <menu-popover trigger="hover">
        <template #content>
          <child-node
            v-model="current"
            :data="item"
          >
          </child-node>
        </template>
        <div class="name">
          <div
            class="truncate"
            :class="item.content_id === curContentId ? 'pl-19px pr-35px' : 'px-19px'"
          >
            {{ item.content_name }}
          </div>
          <div
            v-if="item.content_id === curContentId"
            class="active-info"
          >
            <span class="title">{{ currentName }}</span>
            <span class="time">{{ currentTime }}/{{ totalTime }}</span>
          </div>
        </div>
      </menu-popover>
      <sound-wave
        v-if="item.content_id === curContentId"
        class="wave"
      >
      </sound-wave>
    </div>
  </div>
</template>

<script lang="ts" setup name="ParentNode">
import { useTtsaStore } from '@/store/ttsa'
import useCurrent from '@/hooks/controller/useCurrent';

const { treeStore, currentName, totalTime, currentTime } = useCurrent()

const ttsaStore = useTtsaStore()
const menuData = computed(() => treeStore.menuData);
const curContentId = computed(() => treeStore.current?.content);

const current = computed({
  get: () => treeStore.current || {},
  set: (v) => {
    if (!ttsaStore.paused) ttsaStore.unexpected = true
    ttsaStore.next({ node_id: v.id, content_id: v.content })
  },
})
</script>
<style lang="scss" scoped>
.parent-node {
  padding: 23px 0;

  .main {
    @apply flc justify-start relative;

    &+.main {
      margin-top: 24px;
    }

    .wave {
      @apply absolute w-28px rounded-1/2 h-28px right-9px top-12px pt-7px flex items-baseline justify-center backdrop-blur-3px backdrop-filter;
      border: 1px solid #EEF2F7;
      background: rgba(255, 255, 255, 0.3);
      box-shadow: 0px 2px 4px 0px rgba(2, 29, 88, 0.1);
    }

    .name {
      @apply truncate cursor-pointer;
      font-size: 14px;
      font-weight: 600;
      width: 120px;
      height: 40px;
      border-radius: 20px;
      margin-left: 18px;
      color: #3B5379;
      border: 1px solid rgba(255, 255, 255, 0.3);
      letter-spacing: 1px;
      text-shadow: 0px 2px 17px rgba(0, 0, 0, 0.05), 0px 0px 1px rgba(0, 0, 0, 0.21);

      &:hover {
        background: rgba(255, 255, 255, 0.2);
        box-shadow: 0px 2px 17px 0px rgba(0, 0, 0, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.6);
      }

      .truncate {
        position: relative;
        text-align: center;
        line-height: 40px;
        width: 120px;
        height: 40px;
        border-radius: 20px;
        // padding: 0 19px;
        // padding-left: 19px;
        // padding-right: 35px;
        border: 1px solid transparent;

        &::before {
          @apply absolute-y-center left-7px;
          content: '';
          position: absolute;
          width: 7px;
          height: 7px;
          border-radius: 50%;
          background: linear-gradient(207deg, rgba(255, 255, 255, 0.28) 0%, #FFFFFF 100%);
          box-shadow: 0px 2px 17px 0px rgba(0, 0, 0, 0.05);
        }
      }
    }

    .small {
      border: 1px solid #75869E;
    }

    .circle-line {
      @apply flex items-center absolute z-1 top-1/2;
      width: 23px;
      transform: translateY(-50%);
      left: -8px;

      .circle {
        width: 8px;
        height: 8px;
        background: linear-gradient(147deg, rgba(197, 223, 244, 0.4) 0%, rgba(117, 153, 191, 0.4) 100%);
        box-shadow: 0px 2px 17px 0px rgba(0, 0, 0, 0.05);
        border-radius: 7px;
      }

      .line {
        width: 13px;
        border-bottom: 1px solid #fff;
      }

      .large {
        background: rgba(66, 89, 129, 1);
      }
    }
  }

  .active {
    .name {
      color: #4C7CFF;
      width: 128px;
      padding: 4px;
      height: auto;
      border-radius: 24px;
      margin-left: 13px;

      .truncate {
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 49%, rgba(255, 255, 255, 0.8) 100%);
        box-shadow: 0px 2px 17px 0px rgba(0, 0, 0, 0.05);
        border-color: rgba(255, 255, 255, 0.42);
        backdrop-filter: blur(5px);
      }
    }

    .active-info {
      text-align: center;
      text-shadow: 0px 2px 17px rgba(0, 0, 0, 0.05);
      letter-spacing: 1px;
      margin: 10px 0;

      .title {
        display: block;
        font-size: 12px;
        color: #3B5379;
        line-height: 17px;
        margin-bottom: 3px;
      }

      .time {
        display: block;
        font-size: 8px;
        line-height: 11px;
        color: rgba(59, 83, 121, 0.8);
        transform: scale(0.8);
      }
    }

    .small {
      border: 1px solid #4A7AFB;
      background: #ffffff;
    }

    .circle-line {
      .line {
        border-color: #4C7CFF;
      }

      .circle {
        background: linear-gradient(153deg, #B5E8FF 0%, #4A7AFB 100%);
      }

      .large {
        background: #4A7AFB;
      }
    }
  }
}
</style>